package search

import (
	"github.com/gin-gonic/gin"
	"moments/global"
	"moments/handle/model"
	"moments/handle/request"
	"net/http"
)

// 添加黑名单
func AddBlack(c *gin.Context) {
	var form request.AddBlack
	if err := c.ShouldBind(&form); err != nil {
		c.JSONP(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "参数错误",
		})
		return
	}

	var black model.Blacklist

	black = model.Blacklist{
		UserId:   form.UserId,
		FriendId: form.FriendId,
	}

	if err := black.AddBlack(global.DB); err != nil {
		c.JSONP(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "添加失败",
		})
		return
	}

	c.JSONP(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "黑名单添加成功",
	})

}

// 黑名单列表
func ListBlack(c *gin.Context) {
	var form request.ListBlack
	if err := c.ShouldBind(&form); err != nil {
		c.JSONP(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "参数错误",
		})
		return
	}

	var friend model.Blacklist
	listFriend, err := friend.ListBlack(global.DB, form.UserId)
	if err != nil {
		c.JSONP(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "查询失败",
		})
		return
	}

	c.JSONP(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "黑名单查询成功",
		"Data": map[string]interface{}{
			"list": listFriend,
		},
	})

}
